package com.example.myapplication;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class NewsDetailFragment extends Fragment {

    private static final String ARG_POSITION = "position";

    public static NewsDetailFragment newInstance(int position) {
        NewsDetailFragment fragment = new NewsDetailFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_POSITION, position);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_news_detail, container, false);

        int position = getArguments().getInt(ARG_POSITION);
        News news = NewsFragment.getNewsData().get(position);

        TextView titleTextView = view.findViewById(R.id.news_title);
        TextView authorTextView = view.findViewById(R.id.news_author);
        TextView contentTextView = view.findViewById(R.id.news_content);

        titleTextView.setText(news.getTitle());
        authorTextView.setText("作者：2212260102陈玉朋");
        contentTextView.setText(news.getContent());

        return view;
    }
}